package gamebackend;

/**
 * Data for images of the ship which mark where the ship will
 * teleport if the ship takes damage.
 * @author Jonathan Caddey
 */
public class ShipDecoy {
	/**
	 * How long it takes for decoys to move to a new position.
	 */
	private static final int TRAVEL_TIME = 200;
	private double my_x;
	private double my_y;
	private double my_oldX;
	private double my_oldY;
	private double my_targetX;
	private double my_targetY;
	private int my_timeLeft;
	
	public ShipDecoy(final double the_x, final double the_y) {
//		setXPosition(the_x);
//		setYPosition(the_y);
		moveTo(the_x, the_y);
	}
	public double getXPosition() {
		return my_x;
	}
	public double getYPosition() {
		return my_y;
	}
	public void setXPosition(final double the_targetX) {
		my_x = the_targetX;
	}
	public void setYPosition(final double the_targetY) {
		my_y = the_targetY;
	}
	public void moveX(final double the_targetX) {
		my_targetX = the_targetX;
		my_oldX = my_x;
		my_timeLeft = TRAVEL_TIME;
	}
	public void moveY(final double the_targetY) {
		my_targetY = the_targetY;
		my_oldY = my_y;
		my_timeLeft = TRAVEL_TIME;
	}
	public void moveTo(final double the_x, final double the_y) {
		moveX(the_x);
		moveY(the_y);
	}
	public void step(final int the_deltaTime) {
		if (my_timeLeft > 0) {
			my_timeLeft -= the_deltaTime;
			if (my_timeLeft < 0) {
				my_timeLeft = 0;
			}
			my_x = my_oldX + (my_targetX - my_oldX) * (1 - (double)my_timeLeft / TRAVEL_TIME);
			my_y = my_oldY + (my_targetY - my_oldY) * (1 - (double)my_timeLeft / TRAVEL_TIME);
		}
	}

}
